package com.travel.group.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.travel.group.entity.WxUsers;
import com.travel.group.dao.WxUserMapper;
import com.travel.group.service.WxUserService;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class WxUserServiceImpl extends ServiceImpl<WxUserMapper, WxUsers> implements WxUserService {

    @Override
    public WxUsers getWxUserByUserName(String username) {
        return baseMapper.getWxUserByUserName(username);
    }

    @Override
    public String registerWxUser(WxUsers wxUsers) {
        Date date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        String dateString = format.format(date);
        wxUsers.setUserId(dateString);
        baseMapper.insert(wxUsers);
        return dateString;
    }

    @Override
    public WxUsers checkWxUser(String username, String password) {
        return baseMapper.checkWxUser(username, password);
    }

    @Override
    public List<WxUsers> getAllWxUser(Integer page, Integer limit) {
        PageHelper.startPage(page,limit);
        List<WxUsers> wXusersList = baseMapper.selectList(null);
        return wXusersList;
    }

    @Override
    public Integer countData() {
        return baseMapper.selectCount(null);
    }
}
